package com.siam.package_rider.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siam.package_rider.entity.TbRider;
import com.siam.package_rider.model.param.TbRiderParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * ---------------------------
 * 骑手表 (TbRiderMapper)         
 * ---------------------------
 * 作者：  高品
 * 时间：  2025-03-29 18:55:18
 * ---------------------------
 */
public interface TbRiderMapper extends BaseMapper<TbRider> {

    /**
     * 基础分页查询
     * @param param
     * @return
     */    
    Page<TbRider> page(@Param("page") Page page, @Param("param") TbRiderParam param);

    @ResultMap("BaseResultMap")
    @Select("select * from tb_rider where mobile = #{mobile} order by id desc limit 1 ")
    TbRider selectByMobile(@Param("mobile") String mobile);

    @ResultMap("BaseResultMap")
    @Select("select * from tb_rider where mobile = #{mobile} or id_card = #{idCard} order by id desc limit 1 ")
    TbRider selectByMobileOrIdCard(@Param("mobile") String mobile, @Param("idCard") String idCard);

    @ResultMap("BaseResultMap")
    @Select("select * from tb_rider where username = #{username} or mobile = #{username} order by id desc limit 1 ")
    TbRider selectByUsernameOrMobile(@Param("username") String username);

    @ResultMap("BaseResultMap")
    @Select("select * from tb_rider where username = #{username} order by id desc limit 1 ")
    TbRider selectByUsername(@Param("username") String username);

    //add by 高品 微信OpenId快捷登录,必须绑定了微信才可以快捷登录
    @Select("SELECT id FROM tb_rider  WHERE open_id=#{openId} AND is_deleted = 0 and is_bind_wx='1'")
    Integer  findTbRiderByOpenId(@Param("openId") String openId);

    //微信一键登录
    @Select("SELECT id FROM tb_rider  WHERE mobile=#{mobile} AND is_deleted = 0 and is_bind_wx=1 ")
    Integer  findTbRiderByMobile(@Param("mobile") String mobile);

    //add by 高品 微信OpenId快捷登录
    @Update("update tb_rider set is_bind_wx='1' WHERE mobile=#{mobile} AND is_deleted = 0")
    Integer  updateTbRiderByMobile(@Param("mobile") String mobile);
}